import type { TaskField } from "@/api/services/taskService";

export const convertFormDataToSubmit = (formList: any[], taskId: number) => {
  return (formList || [{}]).map((item) => {
    const fields = Object.entries(item.fields || {}).reduce(
      (acc: any, [id, value]) => {
        acc[id] = {
          field_id: Number.parseInt(id),
          value: value,
        };
        return acc;
      },
      {},
    );
    return {
      task_id: taskId,
      fields,
    };
  });
};

export const renderFormItem = (field: TaskField) => {
  switch (field.fieldType) {
    case "text":
    case "textarea":
      return {
        type: field.fieldType,
        placeholder: field.placeholder || `请输入${field.fieldLabel}`,
      };
    default:
      return null;
  }
};
